﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Spore.Validator
{
    /// <summary>
    /// 是否为时间类型验证器，验证字段是否是时间
    /// </summary>
   public class ValidatorIsDate:ValidatorBase
    {

       private static ValidatorIsDate _default;

        /// <summary>
        /// 默认的验证器
        /// </summary>
       public static ValidatorIsDate Default
        {
            get
            {
                if (_default == null)
                    _default = new ValidatorIsDate();
                return _default;
            }
        }

          private const string DefaultErrMsg = "您输入的时间值格式不正确";
        /// <summary>       
        /// </summary>        
        /// <param name="errMsg">验证不通过时的错误信息</param>
        public ValidatorIsDate(string errMsg)
            : base(errMsg)
        {
        }
        public ValidatorIsDate()
            : base(DefaultErrMsg)
        {
        }

        /// <summary>
        ///验证内容为浮点型
        /// </summary>
        /// <param name="controlToValidate">要验证的控件</param>
        /// <returns></returns>
        public override bool IsValid(Control controlToValidate)
        {
            string content = controlToValidate.Text;
            DateTime tmp;
            return DateTime.TryParse (content, out tmp);
        }
    }
}
